<template>
	<view>
		<block v-for="(item, index) in templates">
			<f-search-bar v-if="item.type == 'search'" :placeholder="item.placeholder"></f-search-bar>
			<swiper v-else-if="item.type == 'swiper'" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="px-2">
				<swiper-item class="flex justify-center" v-for="(subItem, index) in item.data" :key="index">
					<image :src="subItem.src" mode="aspectFill" style="width: 720rpx; height: 300rpx;" class="rounded"></image>
				</swiper-item>
			</swiper>
			<icon-nav v-else-if="item.type == 'icons'" :list="item.data"></icon-nav>
			<coupon-list v-else-if="item.type == 'coupon'"></coupon-list>
			<template v-else-if="item.type == 'promotion'">
				<view class="divider"></view>
				<view class="flex align-center py-3 px-2">
					<text class="font-md font-weight-bold">{{item.listType == 'group' ? '拼团' : '秒杀'}}</text>
				</view>
				<scroll-view scroll-x="true" class="scroll-row" >
					<course-list v-for="(item, index) in groupList" :key="index" :item="item" type="two"></course-list>
				</scroll-view>
			</template>
			<template v-else-if="item.type == 'list'">
				<view class="divider"></view>
				<view class="flex align-center justify-between py-3 px-2">
					<text class="font-md font-weight-bold">{{item.title}}</text>
					<text class="text-light-muted" v-if="item.showMore">查看更新</text>
				</view>
				<view >
					<course-list v-for="(subItem, index) in item.data" :key="index" :item="subItem" :type="item.listType"></course-list>
				</view>
			</template>
			<template v-else-if="item.type == 'imageAd'">
				<view class="divider"></view>
				<image :src="item.data" mode="aspectFill" style="width: 750rpx; height: 360rpx;"></image>
			</template>
		</block>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				templates: [],
				
				
				groupList: [
					{
						"group_id": 19,
						"id": 12,
						"title": "unicloud商城全栈开发",
						"cover": "http://demo-mp3.oss-cn-shenzhen.aliyuncs.com/egg-edu-demo/10ccf3a973f5193bec3c.png",
						"price": "4.00",
						"t_price": "10.00",
						"type": "media",
						"start_time": "2021-04-15T16:00:00.000Z",
						"end_time": "2022-05-16T16:00:00.000Z"
					},
					{
						"group_id": 19,
						"id": 12,
						"title": "unicloud商城全栈开发",
						"cover": "http://demo-mp3.oss-cn-shenzhen.aliyuncs.com/egg-edu-demo/10ccf3a973f5193bec3c.png",
						"price": "4.00",
						"t_price": "10.00",
						"type": "media",
						"start_time": "2021-04-15T16:00:00.000Z",
						"end_time": "2022-05-16T16:00:00.000Z"
					},
				],
				list: [
					{
						"group_id": 19,
						"id": 12,
						"title": "unicloud商城全栈开发",
						"cover": "http://...png",
						"price": "4.00",
						"t_price": "10.00",
						"type": "media",
						"start_time": "2021-04-15T16:00:00.000Z",
						"end_time": "2022-05-16T16:00:00.000Z"
					},
					{
						"group_id": 19,
						"id": 12,
						"title": "unicloud商城全栈开发",
						"cover": "http://...png",
						"price": "4.00",
						"t_price": "10.00",
						"type": "media",
						"start_time": "2021-04-15T16:00:00.000Z",
						"end_time": "2022-05-16T16:00:00.000Z"
					},
				]

			}
		},
		methods: {
			getData() {
				uni.request({
					url: 'http://demonuxtapi.dishait.cn/mobile/index',
					method: 'GET',
					header: {
						appid: 'bd9d01ecc75dbbaaefce'
					},
					success: (res) => {
						if(res.statusCode != 200 || res.data.msg == 'fail') {
							uni.showToast({
								title: res.data.data || '请求失败'
							})
							return
						} else {
							this.templates = res.data.data
						}
						console.log(res)
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				})
			}
				
		},
		onPullDownRefresh() {
			this.getData()
		},
		created() {
			this.getData()
		}
	}
</script>
<style>

</style>